<?php
/**
 * Created by IntelliJ IDEA.
 * User: peya
 * Date: 14.12.11
 * Time: 11:55
 * To change this template use File | Settings | File Templates.
 */

class Knihovna_Model_DbTable_Lokace extends Zend_Db_Table_Abstract
{

    //nazev tabulky
   protected $_name = 'lokace';

    //PK
   protected $_primary = 'id_lokace';

    //FK
   protected $_dependentTables = array('Kniha');

   // fce pro praci s DB tabulkami

    public function getLokace($id_lokace)
    {
       $id_lokace = (int)$id_lokace;
       $row = $this->fetchRow('id_lokace = ' . $id_lokace);

        if (!$row) {
            throw new Exception("Nelze nalezt lokaci s ID $id_lokace");
        }
        return $row->toArray();
    }

    public function addLokace($mesto, $ulice)
    {
        $data = array(
        'mesto' => $mesto,
        'ulice' => $ulice
        );
        $this->insert($data);
    }

    public function editLokace($id_lokace, $mesto, $ulice)
    {
        $data = array(
        'mesto' => $mesto,
        'ulice' => $ulice
        );
        $this->update($data, 'id_lokace =' . (int)$id_lokace );
    }

    public function deleteLokace($id_lokace)
    {
        $this->delete('id_lokace =' . (int)$id_lokace );
    }
}
